package com.skcc.ngms.matest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.skcc.alopex.common.activity.MainActivity;
import com.skcc.alopex.common.delegator.AlopexControllerDelegator;

public class NotificationMessageNewActivity extends MainActivity {

	private MainActivity mActivity = MainActivity.mInstance;
	private String itemId = null;
	private String itemChangekey = null;
	    	
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	    itemId = (String) getIntent().getStringExtra("itemId");
	    itemChangekey = (String) getIntent().getStringExtra("itemChangekey");
	    
	    AlopexControllerDelegator.getInstance(mActivity).navigateWithUrl("/uidef/Mail_View.html", "mailId="+escape(itemId)+"&changeKey=" + escape(itemChangekey));
	    
//	    NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
	    // Cancel Notification
//	    nm.cancel(1234);
	    
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if(itemId==null){
			itemId = (String) getIntent().getExtras().get("itemId");
		    itemChangekey = (String) getIntent().getExtras().get("itemChangekey");
		    AlopexControllerDelegator.getInstance(mActivity).navigateWithUrl("/uidef/Mail_View.html", "mailId="+escape(itemId)+"&changeKey=" + escape(itemChangekey));
		    this.finish();
		}
	}
	
	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		if(itemId==null){
		itemId = (String) getIntent().getExtras().get("itemId");
	    itemChangekey = (String) getIntent().getExtras().get("itemChangekey");
	    AlopexControllerDelegator.getInstance(mActivity).navigateWithUrl("/uidef/Mail_View.html", "mailId="+escape(itemId)+"&changeKey=" + escape(itemChangekey));
	    this.finish();
		}
	}
	

	public String escape(String src) {
		int i;
		char j;
		StringBuffer tmp = new StringBuffer();
		tmp.ensureCapacity(src.length() * 6);
		for (i = 0; i < src.length(); i++) {
			j = src.charAt(i);
			if (Character.isDigit(j) || Character.isLowerCase(j)
					|| Character.isUpperCase(j))
				tmp.append(j);
			else if (j < 256) {
				tmp.append("%");
				if (j < 16)
					tmp.append("0");
				tmp.append(Integer.toString(j, 16));
			} else {
				tmp.append("%u");
				tmp.append(Integer.toString(j, 16));
			}
		}
		return tmp.toString();
	}
}
